package com.sanley.piss.web.controller;

import com.sanley.piss.model.exceptionUtil.json.JsonResult;
import com.sanley.piss.model.po.DictionaryData;
import com.sanley.piss.model.vo.DictionaryDataVO;
import com.sanley.piss.web.service.mapper.IDictionaryDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * Create By  on 2021/3/22.
 *
 * @author 张凯大天才
 */
@Api(value = "数据字典数据controller", tags = "数据字典数据操作接口")
@RestController
@RequestMapping("/dicdata")
public class DictionaryDataController {

    @Autowired
    private IDictionaryDataService service;

    @ApiOperation(value = "增加一条记录")
    @RequestMapping(value = "/insert", method = RequestMethod.PUT)
    public JsonResult<Object> insert(@Valid DictionaryDataVO dictionaryData) {
        service.insert(dictionaryData);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID删除多条记录")
    @RequestMapping(value = "/delete/{ids}", method = RequestMethod.DELETE)
    public JsonResult<Object> delete(@PathVariable("ids") Integer[] ids) {
        service.removeByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID修改一条记录")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JsonResult<Object> update(@Valid DictionaryData dictionaryData) {
        service.updateById(dictionaryData);
        return JsonResult.success();
    }

    @ApiOperation(value = "查询ID 类型 名字 ")
    @RequestMapping(value = "/selectDataIdAndName", method = RequestMethod.GET)
    public JsonResult<List<Map<Integer, Object>>> selectDataIdAndName() {
        return JsonResult.success(service.selectDataIdAndName());
    }

    @ApiOperation(value = "根据id查询一条数据")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<DictionaryData> selectById(Integer id) {
        return JsonResult.success(service.selectById(id));
    }
}
